import React from 'react';
import {Platform, View} from 'react-native';
import {useTranslation} from 'react-i18next';
import {useSelector} from 'react-redux';
import {RootState} from '@/store';
import {useMMKVString} from '@/hooks/useMMkv';
import {Radio} from 'tsun-smart-ui';
import HotUpdate from 'react-native-ota-hot-update';
import NativeLaunchManager from '~/specs/NativeLaunchManager';
interface Language {
  value: string;
  label: string;
}

const LanguageSettingsScreen = () => {
  const {i18n} = useTranslation();
  const [selectedLanguage, setSelectedLanguage] = useMMKVString('language');
  // 可用语言列表
  const languages = useSelector<RootState, Language[]>(
    state => state.language.supportedLanguages,
  );
  // 更新语言设置
  const handleLanguageChange = async (langCode: string) => {
    setSelectedLanguage(langCode);
    if(Platform.OS ==='ios'){
      await NativeLaunchManager.show()
    }
    HotUpdate.resetApp();
  };

  return (
    <View className="rounded-xl bg-background-0 mx-4 mt-4">
      <Radio
        data={languages}
        value={selectedLanguage!}
        onChange={handleLanguageChange}
      />
    </View>
  );
};
export default LanguageSettingsScreen;
